package it.polimi.digitalstate.webbeans;

import it.polimi.digitalstate.dto.PartyDTO;
import it.polimi.digitalstate.manager.PartyManagerLocal;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="electionPartyBean")
@SessionScoped
public class ElectionPartyBean {
	@EJB
	private PartyManagerLocal ejb;
	


	private PartyDTO[] party;
	int i=0;
	
	@PostConstruct
	private void init() {
		
		Object[] list_o =		ejb.getListOfParty().toArray();
		party = new PartyDTO[list_o.length];
		for(int i=0;i<list_o.length;i++){
			party[i]=(PartyDTO)list_o[i];
		}
		i=0;
	}
	
	public String next(){
		if(i<party.length-1)
		i++;
		return "electionparty.xhtml?faces-redirect=true";
	}
	public String previus(){
		if(i>0)
			i--;
		return "electionparty.xhtml?faces-redirect=true";
	}
	public boolean hasPrevious(){
		System.out.println("HASPRE?");
		return i>=1;
	}
	public boolean hasNext(){
		System.out.println("HASNEX?");
		return i<party.length-1;
	}
	public PartyDTO getCurrentparty() {
		return party[i];
	}
	public String vote() {
		return "electionmemberlist?faces-redirect=true&partyname="+party[i].getName();
	}
	
}
